#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace Test
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;

        #region Walking Animations
        //Down
        AnimateTexture AshWalkDown;
        AnimateTexture AshStandDown;
        //Left
        AnimateTexture AshWalkLeft;
        AnimateTexture AshStandLeft;
        //Right
        AnimateTexture AshWalkRight;
        AnimateTexture AshStandRight;
        //Up
        AnimateTexture AshWalkUp;
        AnimateTexture AshStandUp;
        #endregion

        KeyboardState keyboardState;
        KeyboardState previousKeyboardState;

        float XPos1 = 500.0f;
        float YPos1 = 500.0f;

        float movespeed = 1.0f;

        #region Booleans
        bool DownPress;
        bool UpPress;
        bool RightPress;
        bool LeftPress;
        #endregion

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
        }

        protected override void Initialize()
        {


            base.Initialize();
        }

        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                #region Create AnimateTexture
                //Down
                AshWalkDown = new AnimateTexture();
                AshStandDown = new AnimateTexture();
                //Left
                AshWalkLeft = new AnimateTexture();
                AshStandLeft = new AnimateTexture();
                //Right
                AshWalkRight = new AnimateTexture();
                AshStandRight = new AnimateTexture();
                //Up
                AshWalkUp = new AnimateTexture();
                AshStandUp = new AnimateTexture();
                #endregion

                #region Load Spritesheet
                //Down
                AshWalkDown.Load(content, "Content\\Down\\poke");
                AshStandDown.Load(content, "Content\\Down\\ashstanding");
                //Left
                AshWalkLeft.Load(content, "Content\\Left\\WalkLeft");
                AshStandLeft.Load(content, "Content\\Left\\AshStandLeft");
                //Right
                AshWalkRight.Load(content, "Content\\Right\\WalkRight");
                AshStandRight.Load(content, "Content\\Right\\AshStandRight");
                //Up
                AshWalkUp.Load(content, "Content\\Up\\WalkUp");
                AshStandUp.Load(content, "Content\\Up\\AshStandUp");
                #endregion
            }


            // TODO: Load any ResourceManagementMode.Manual content
        }

        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
                // TODO: Unload any ResourceManagementMode.Automatic content
                content.Unload();
            }

            // TODO: Unload any ResourceManagementMode.Manual content
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            keyboardState = Keyboard.GetState();

            #region Animate the Texture
            //Down
            AshWalkDown.Animate(4, 2, 15, 18, content, graphics, gameTime);
            AshStandDown.Animate(1, 1, 15, 18, content, graphics, gameTime);
            //Left
            AshWalkLeft.Animate(3, 2, 15, 18, content, graphics, gameTime);
            AshStandLeft.Animate(1, 1, 15, 18, content, graphics, gameTime);
            //Right
            AshWalkRight.Animate(2, 2, 15, 18, content, graphics, gameTime);
            AshStandRight.Animate(1, 1, 15, 18, content, graphics, gameTime);
            //Up
            AshWalkUp.Animate(4, 2, 15, 18, content, graphics, gameTime);
            AshStandUp.Animate(1, 1, 15, 18, content, graphics, gameTime);
            #endregion

            #region Keyboard Controls
            if (keyboardState.IsKeyDown(Keys.Down))
            {
                YPos1 += movespeed;
                DownPress = true;
                UpPress = false;
                LeftPress = false;
                RightPress = false;
            }

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                XPos1 -= movespeed;
                LeftPress = true;
                RightPress = false;
                UpPress = false;
                DownPress = false;
            }

            if (keyboardState.IsKeyDown(Keys.Up))
            {
                YPos1 -= movespeed;
                LeftPress = false;
                RightPress = false;
                UpPress = true;
                DownPress = false;
            }

            if (keyboardState.IsKeyDown(Keys.Right))
            {
                XPos1 += movespeed;
                LeftPress = false;
                RightPress = true;
                UpPress = false;
                DownPress = false;
            }
            #endregion

            #region Etc.
            if (XPos1 < -5)
            {
                XPos1 = 800;
            }
            else if (XPos1 > 800)
            {
                XPos1 = 0;
            }

            if (YPos1 < 0)
            {
                YPos1 = 600;
            }
            else if (YPos1 > 600)
            {
                YPos1 = 0;
            }
            #endregion

            previousKeyboardState = keyboardState;

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            #region Walking Down
            if (DownPress && !keyboardState.IsKeyDown(Keys.Down))
            {
                AshStandDown.Draw(XPos1, YPos1, graphics);
            }

            if (DownPress && keyboardState.IsKeyDown(Keys.Down))
            {
                AshWalkDown.Draw(XPos1, YPos1, graphics);
            }

            if (!DownPress && !UpPress && !RightPress && !LeftPress)
            {
                AshStandDown.Draw(XPos1, YPos1, graphics);
            }
            #endregion

            #region Walking Left
            if (LeftPress && keyboardState.IsKeyDown(Keys.Left))
            {
                AshWalkLeft.Draw(XPos1, YPos1, graphics);
            }

            if (LeftPress && !keyboardState.IsKeyDown(Keys.Left))
            {
                AshStandLeft.Draw(XPos1, YPos1, graphics);
            }
            #endregion

            #region Walking Right
            if (RightPress && keyboardState.IsKeyDown(Keys.Right))
            {
                AshWalkRight.Draw(XPos1, YPos1, graphics);
            }

            if (RightPress && !keyboardState.IsKeyDown(Keys.Right))
            {
                AshStandRight.Draw(XPos1, YPos1, graphics);
            }
            #endregion

            #region Walking Up
            if (UpPress && keyboardState.IsKeyDown(Keys.Up))
            {
                AshWalkUp.Draw(XPos1, YPos1, graphics);
            }

            if (UpPress && !keyboardState.IsKeyDown(Keys.Up))
            {
                AshStandUp.Draw(XPos1, YPos1, graphics);
            }
            #endregion

            base.Draw(gameTime);
        }
    }
}
